/**
 * @format
 * @Author: TC
 * @Date: 2023-07-27 16:52:46
 * @Last Modified by:   TC
 * @Last Modified time: 2023-07-27 16:52:46
 */

import { _decorator, Canvas, Component, Label, Node, Sprite } from "cc";
import { app } from "../FrameWork/App";
import { VirtualScrollView } from "../FrameWork/CCComponent/UI/VirtualScrollView";
const { ccclass, property } = _decorator;

@ccclass("TestScene")
export class TestScene extends Component {
    @property(Canvas)
    canvas: Canvas = null;
    @property(VirtualScrollView)
    vs: VirtualScrollView = null;

    start() {}

    update(deltaTime: number) {}

    onTest(): void {
        // windowMgr.openWindow(mBundleConst.Setting, "settingWindow");
        // sceneMgr.runScene("MianScene", mBundleConst.Hall)
        // postEffectMgr.open();
        let data = [];
        for (let i = 0; i < 200; i++) {
            data[i] = i;
        }
        this.vs.setListData(data, this.onRenderItem);
    }

    private onRenderItem(index: number, node: Node): void {
        app.mComponent.setNodeLabel(node.getChildByName("Label"), "" + index);

        node.off(Node.EventType.TOUCH_END);
        node.on(
            Node.EventType.TOUCH_END,
            () => {
                app.mConsole.log(index);
            },
            node
        );
    }
}

// private checkOnSlope(): boolean {
//     let bSlpoe = false;

//     this._posLeft.x = -this._width / 2;
//     this._posLeft.y = 0;

//     this._posRight.x = this._width / 2;
//     this._posRight.y = 0;

//     //左
//     let p0: Vec3 = v3(),
//         p1: Vec3 = v3();
//     p0 = this.node.getComponent(UITransform).convertToWorldSpaceAR(this._posLeft);
//     p1.x = p0.x - this._distanceSlope;
//     p1.y = p0.y;
//     let result = PhysicsSystem2D.instance.raycast(p0, p1, ERaycast2DType.All);
//     if (result && result.length > 0) {
//         for (let i = 0; i < result.length; i++) {
//             if (result[0].collider.group) {
//                 bSlpoe = true;
//                 this._normal = result[0].normal.normalize();
//             }
//         }
//     }
//     //右
//     p0 = this.node.getComponent(UITransform).convertToWorldSpaceAR(this._posRight);
//     p1.x = p0.x + this._distanceSlope;
//     p1.y = p0.y;
//     result = PhysicsSystem2D.instance.raycast(p0, p1, ERaycast2DType.All);
//     if (result && result.length > 0) {
//         for (let i = 0; i < result.length; i++) {
//             if (result[0].collider.group) {
//                 bSlpoe = true;
//                 this._normal = result[0].normal.normalize();
//             }
//         }
//     }
//     return bSlpoe;
// }

// private updateGroundState(): void {
//     let friction = this._bSlope ? 99999 : 0;
//     if (friction != this._collider2D.friction) {
//         this._collider2D.friction = friction;
//         this._collider2D.apply();
//     }

//     let g = this._bSlope ? 0 : 12;
//     this._rb.gravityScale = g;
// }
/**
 * 获取与法线垂直的方向
 * @param normal
 * @returns
 */
// private getSlopeDir(normal: Vec2): Vec2 {
//     if (0 == normal.x) {
//         return v2(1, 0);
//     }
//     return v2(Math.abs(-normal.y / normal.x), 1).normalize();
// }
